package spring_mvc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import spring_mvc.model.User;
import spring_mvc.service.UserService;


@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/users")
    public ModelAndView getUsers(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("users");
        modelAndView.addObject("users",userService.findAll());
        return modelAndView;
    }

    @RequestMapping("/users/save")
    public String saveUser(User user){
        System.out.println(user);
        int res = userService.save(user);
        return "users";
    }

}
